<template>
  <div id="main" style="width: 600px;height: 400px;"></div>
</template>
<script>
import echarts from "echarts";
import chartStore from "../store/index";
import { mapGetters, mapActions } from "vuex";
// import  $  from "jquery";
export default {
  name: "customizedCompoenet",
  data() {
    return {};
  },
  created() {
    this.$store.registerModule("customized", chartStore);
  },
  computed: {
    ...mapGetters({
      xAxisData: "getDate"
    })
  },
  methods: {
    ...mapActions(["getData"])
  },
  mounted() {
    this.$nextTick(function() {
      this.getData().then(() => {
        var myChart = echarts.init(document.getElementById("main"));
        // 指定图表的配置项和数据
        var option = {
          title: {
            text: "ECharts 入门示例"
          },
          tooltip: {},
          legend: {
            data: ["销量"]
          },
          xAxis: {
            data: this.xAxisData
          },
          yAxis: {},
          series: [
            {
              name: "销量",
              type: "bar",
              data: [5, 20, 36, 10, 10, 20, 20, 40]
            }
          ]
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
      });
    });
  },
  destroyed(){
    this.$store.unregisterModule("customized");
  }
};
</script>



